|
The null coalescing operator (called the Logical Defined-Or operator in Perl) is a binary operator that is part of the syntax for a basic conditional expression in several programming languages, including C#,〔(?? Operator (C# Reference) )〕 Perl as of version 5.10,〔(// Operator (Perl Reference) )〕 Swift.〔(Nil Coalescing Operator )〕 and PHP 7.0.0 〔(PHP 7.0.0 RC 7 Released )〕 In contrast to the ternary conditional if operator used as x ? x : y , but like the binary Elvis operator used as x ?: y , the null coalescing operator is a binary operator and thus evaluates its operands at most once, which is significant if the evaluation of x has side-effects.==C#== In C#, the null coalescing operator is ?? . It is most often used to simplify null expressions as follows:For example, if one wishes to implement some C# code to give a page a default title if none is present, one may use the following statement: instead of the more verbose or The three forms are logically equivalent. The operator can also be used multiple times in the same expression: Once a non-null value is assigned to number, or it reaches the final value (which may or may not be null), the expression is completed. 抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)』 ■ウィキペディアで「Null coalescing operator」の詳細全文を読む スポンサード リンク
|